package com.itheima;

import com.itheima.dao.CourseDao;
import com.itheima.domain.Course;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class CourseServiceDemo {
    public static void main(String[] args) throws IOException {
        InputStream in = Resources.getResourceAsStream("MybaitsConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        SqlSession sqlSession = factory.openSession();

        CourseDao mapper = sqlSession.getMapper(CourseDao.class);
        List<Course> all = mapper.findAll();
        for (Course course : all) {
            System.out.println(course);
        }

        sqlSession.close();
    }
}
